﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Web;
using System.Xml;
using Ext.Net;
using AppGisena.Models;
using System.Linq;

using AppGISENA.ObjetosNegocio;
using AppGISENA.UIServicios;

namespace Ext.Net.Examples.Examples.Form.ComboBox.Custom_Search
{
    public class Plant
    {

          private BDGISENAEntities GisenaDb = new BDGISENAEntities(); 


        
        public Plant(long Id_Prod_Final,  string Nomb_Prod, string Descrip_Prod, int id_prod_base, int id_tp_Prod)
        {




            this.Id_Prod_Final = Id_Prod_Final;
            this.Nomb_Prod = Nomb_Prod;
            this.Descrip_Prod = Descrip_Prod;
            this.id_prod_base = id_prod_base;
            this.id_tp_Prod = id_tp_Prod;
          //  this.Botanical = botanical;
          //  this.Common = common;
        }

        public Plant()
        {
        }

        public long Id_Prod_Final { get; set; }
        public string Nomb_Prod { get; set; }
        public string Descrip_Prod { get; set; }
        public int id_prod_base { get; set; }
        public long id_tp_Prod { get; set; }

        public static Paging<ProductosBO> PlantsPaging(int start, int limit, string sort, string dir, string filter)
        {
            UnidadProductivaServicios myservicio=new UnidadProductivaServicios(); 
           // BDGISENAEntities2 gisenadb=new BDGISENAEntities2(); 
            List<ProductosBO> plants =myservicio.GetProductos();// gisenadb.Productos.Local.;

            if (!string.IsNullOrEmpty(filter) && filter != "*")
            {
                plants.RemoveAll(plant => !plant.Nomb_Prod.ToLower().StartsWith(filter.ToLower()));
            }

            if (!string.IsNullOrEmpty(sort))
            {
                plants.Sort(delegate(ProductosBO x, ProductosBO y)
                {
                    object a;
                    object b;

                    int direction = dir == "DESC" ? -1 : 1;

                    a = x.GetType().GetProperty(sort).GetValue(x, null);
                    b = y.GetType().GetProperty(sort).GetValue(y, null);

                    return CaseInsensitiveComparer.Default.Compare(a, b) * direction;
                });
            }

            if ((start + limit) > plants.Count)
            {
                limit = plants.Count - start;
            }

            List<ProductosBO> rangePlants = (start < 0 || limit < 0) ? plants : plants.GetRange(start, limit);

            return new Paging<ProductosBO>(rangePlants, plants.Count);
        }

      
    }
}